#ifndef _SYSCFG_HW_H_
#define _SYSCFG_HW_H_

#include "soc.h"

typedef struct {
	_RW MEMRMP;       /*!< SYSCFG memory remap register,                      offset: 0x00      */
	_RW PMC;          /*!< SYSCFG peripheral mode configuration register,     offset: 0x04      */
	_RW EXTICR[4];    /*!< SYSCFG external interrupt configuration registers, offset: 0x08-0x14 */
	_NU RESERVED[2];  /*!< Reserved, 0x18-0x1C                                                  */
	_RW CMPCR;        /*!< SYSCFG Compensation cell control register,         offset: 0x20      */
} SYSCFG_Struct;

extern SYSCFG_Struct SOC_SYSCFG;

/**
 * 存储器地址重映射，复位后该值由BOOT[1:0]两个引脚设置，ROM从0x00000000地址启
 * 动，故BOOT引脚可以修改启动的存储器，ROM去0x00000004取复位向量，进而跳转到了
 * 对应的存储器，当然程序链接到0地址也能够正常运行。在重映射模式下，CPU可以通
 * 过ICode总线（而不是System）访问外部存储，可以提高性能。
 */
#define SYSCFG_MEMRMP_FLASH   (0x1U<<0)  /* 将0x08000000映射到0x00000000 */
#define SYSCFG_MEMRMP_FSMC    (0x2U<<0)  /* 将0x60000000映射到0x00000000，
                                            FSMC Bank1的前两个区域（NOR/PSRAM1
                                            和NOR/PSRAM2可以映射） */
#define SYSCFG_MEMRMP_SRAM    (0x3U<<0)  /* 将0x20000000映射到0x00000000 */

/**
 * 以太网PHY接口选择
 */
#define SYSCFG_PMC_MII        (0x0U<<23)
#define SYSCFG_PMC_RMII       (0x1U<<23)

/**
 * 外部中断线映射
 */
#define SYSCFG_EXTICR0_0_3D(n, val)   ((val)<<(((n)-0)*4))
#define SYSCFG_EXTICR1_4_7D(n, val)   ((val)<<(((n)-4)*4))
#define SYSCFG_EXTICR2_8_11D(n, val)  ((val)<<(((n)-8)*4))
#define SYSCFG_EXTICR3_12_15D(n, val) ((val)<<(((n)-12)*4))
#define SYSCFG_EXTICR_MASK            0xFU
#define SYSCFG_EXTICR_PA              0x0U
#define SYSCFG_EXTICR_PB              0x1U
#define SYSCFG_EXTICR_PC              0x2U
#define SYSCFG_EXTICR_PD              0x3U
#define SYSCFG_EXTICR_PE              0x4U
#define SYSCFG_EXTICR_PF              0x5U
#define SYSCFG_EXTICR_PG              0x6U
#define SYSCFG_EXTICR_PH              0x7U
#define SYSCFG_EXTICR_PI              0x8U  /* EXTI4中不存在PI引脚 */

/**
 * IO补偿单元
 */
#define SYSCFG_CMPCR_DIS              (0x0U<<0)
#define SYSCFG_CMPCR_EN               (0x1U<<0)
#define _SYSCFG_IsCmpReady(dev)       ((dev).CMPCR & (0x1U<<8))

#endif /* _SYSCFG_HW_H_ */
